//
//  VideoHelper.m
//  MGLOL盒子
//
//  Created by lanou3g on 15/12/4.
//  Copyright © 2015年 张明. All rights reserved.
//

#import "VideoHelper.h"
#import "VideoModel.h"
#import "AFHTTPSessionManager.h"
#import "FenLeiVideo.h"
static VideoHelper *videoHelp = nil;
@implementation VideoHelper
- (void)getVideoDataWithUrl:(NSString *)url FenLei:(NSString *)fenLei successData:(void (^)(NSMutableArray *array))success fail:(void (^)(NSError *err))fail {
    //判断URL是否为空
    if (!url) {
        NSError *err = [NSError errorWithDomain:@"Url为空" code:1 userInfo:nil];
        fail(err);
        return;
    }
    //遍历数组，封装数据
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
//        NSLog(@"%@",responseObject);
        NSArray *arr = responseObject;
          _allDataMutableArr = [[NSMutableArray alloc]init];
            for (NSDictionary* a in arr) {
                     FenLeiVideo *fenzumodel = [[FenLeiVideo alloc]init];
                       [fenzumodel setValuesForKeysWithDictionary:a];
//                    NSLog(@"%@",fenzumodel.group);
                    if ([fenzumodel.group isEqualToString:fenLei]) {
                        for (NSDictionary *d in a[@"subCategory"]) {
                            VideoModel *model = [[VideoModel alloc]init];
                            [model setValuesForKeysWithDictionary:d];
                            [_allDataMutableArr addObject:model];
//                                NSLog(@"-------%@",model.icon);
                        }
                }
                        }
        success(_allDataMutableArr);
//      NSLog(@"!!!!!!!!%@",_allDataMutableArr);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"%@",error);
    }];
}
+(instancetype)shareVideoWithHelpData {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        videoHelp = [[VideoHelper alloc]init];
    });
    return videoHelp;
}

@end
